import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    userInfo: null,
    token: null
  },
  mutations: {
    setUserInfo(state, data) {
      state.userInfo = data.userInfo
      state.token = data.token
      localStorage.setItem('userInfo', JSON.stringify(data.userInfo))
      localStorage.setItem('token', data.token)
    },
    clearUserInfo(state) {
      state.userInfo = null
      state.token = null
      localStorage.removeItem('userInfo')
      localStorage.removeItem('token')
    }
  }
})